/*   time:2019-06-13 20:39:24*/
var t = getApp(),
    a = t.requirejs("core");
t.requirejs("foxui"), Page({
    data: {
        icons: t.requirejs("icons"),
        page: 1,
        loading: !1,
        loaded: !1,
        isedit: !1,
        isCheckAll: !1,
        checkObj: {},
        checkNum: 0,
        list: []
    },
    onLoad: function(a) {
        t.url(a), this.getList()
    },
    onShow: function() {
        t.getCache("isIpx") ? this.setData({
            isIpx: !0,
            iphonexnavbar: "fui-iphonex-navbar",
            paddingb: "padding-b"
        }) : this.setData({
            isIpx: !1,
            iphonexnavbar: "",
            paddingb: ""
        })
    },
    onReachBottom: function() {
        this.data.loaded || this.data.list.length == this.data.total || this.getList()
    },
    onPullDownRefresh: function() {
        wx.stopPullDownRefresh()
    },
    getList: function() {
        var i = this;
        i.setData({
            loading: !0
        }), a.get("member/history/get_list", {
            page: i.data.page
        }, function(t) {
            var a = {
                loading: !1,
                loaded: !0,
                total: t.total,
                pagesize: t.pagesize,
                show: !0
            };
            0 < t.list.length && (a.page = i.data.page + 1, a.list = i.data.list.concat(t.list), t.list.length < t.pagesize && (a.loaded = !0)), i.setData(a)
        })
    },
    itemClick: function(t) {
        var i = this,
            e = a.pdata(t).id,
            s = a.pdata(t).goodsid;
        if (i.data.isedit) {
            var c = i.data.checkObj,
                n = i.data.checkNum;
            c[e] ? (c[e] = !1, n--) : (c[e] = !0, n++);
            var o = !0;
            for (var h in c) if (!c[h]) {
                o = !1;
                break
            }
            i.setData({
                checkObj: c,
                isCheckAll: o,
                checkNum: n
            })
        } else wx.navigateTo({
            url: "/pages/goods/detail/index?id=" + s
        })
    },
    btnClick: function(t) {
        var i = this,
            e = t.currentTarget.dataset.action;
        if ("edit" == e) {
            for (var s in c = {}, this.data.list) c[this.data.list[s].id] = !1;
            i.setData({
                isedit: !0,
                checkObj: c,
                isCheckAll: !1
            })
        } else if ("delete" == e) {
            var c = i.data.checkObj,
                n = [];
            for (var s in c) c[s] && n.push(s);
            if (n.length < 1) return;
            a.confirm("删除后不可恢复，确定要删除吗？", function() {
                a.post("member/history/remove", {
                    ids: n
                }, function(t) {
                    i.setData({
                        isedit: !1,
                        checkNum: 0,
                        page: 0,
                        list: []
                    }), i.getList()
                })
            })
        } else "finish" == e && i.setData({
            isedit: !1,
            checkNum: 0
        })
    },
    checkAllClick: function() {
        var t = !this.data.isCheckAll,
            a = this.data.checkObj,
            i = {
                isCheckAll: t,
                checkObj: a
            };
        for (var e in a) i.checkObj[e] = !! t;
        i.checkNum = t ? this.data.list.length : 0, this.setData(i)
    }
});